import * as React from 'react';
import { Form, Divider } from 'antd';

import auth from '../../utils/auth'

import validation from '../../utils/validation'
import ITable from "../../components/ITable"
import { Link } from 'react-router-dom';
import IAddress from '../../components/IAddress';

const url: string = "/admin/accounts/search";
const rowKey: string = "id";

const filter: any[] = [
    {
        type: "select",
        name: "status",
        label: "",
        items: [{
            key: "",
            value: "全部"
        }, {
            key: "INACTIVE",
            value: "未共识"
        },
        {
            key: "NODELESS",
            value: "共识失败"
        },
        {
            key: "NODEFUL",
            value: "共识成功"
        },
        {
            key: "WITHDRAW",
            value: "退本"
        }]
    },
    {
        type: "text",
        name: "q",
        label: "关键字",
        validation: validation.string,
    },
];

const filterData = {
    q: "",
    status: ""
};



const ITButton: React.FC = () => {
    return <>
        {/* <IExport url="/admin/wallet/export" /> */}
    </>
}

let columns: any[] = [{
    title: "ID",
    dataIndex: "id",
},
{
    title: "账户信息",
    width: 360,
    render: (text: any, record: any) => {
        return <>
            <p>账号：{record.email}</p>
            <p>注册时间：{record.account.createTime}</p>
            <p>联系电话：{record.mobile}</p>
            <p>绑定钱包地址：<IAddress username={record.username} /></p>
        </>
    }
},
{
    title: "资产",
    width: 240,
    render: (text: any, record: any) => {
        return <>
            <p>共识卷：{record.account.agreement}</p>
            <p>本金：{record.account.capital}</p>
            <p>GW：{record.account.token}</p>
            <p>可用：{record.account.available}</p>
        </>
    }
},
{
    title: "收益",
    width: 240,
    render: (text: any, record: any) => {

        return <>
            <p>推广收益：{record.account.shareRev}</p>
            <p>共识券：{record.account.agreementRev}</p>
            <p>共识成功：{record.account.benefit}</p>
            <p>共识失败：{record.account.agreeFailRev}</p>
        </>
    }
},
{
    title: "业绩",
    dataIndex: "account.subNode",
},
{
    title: "共识状态",
    fixed: 'right',
    render: (text: any, record: any) => {
        const status: any = {
            INACTIVE: "未共识",
            NODELESS: "共识失败",
            NODEFUL: "共识成功",
            WITHDRAW: "退本"
        };
        return <>{status[record.account.accStatus]}</>
    }
},
{
    title: "操作",
    fixed: 'right',
    render: (text: any, record: any) => {
        return <>
            {
                auth(["BOSS"]) ? <Link to={{ pathname: "/user/Archite", search: `?id=${record.id}` }} >推广架构</Link> : null
            }
            <p>
                <Link to={{ pathname: "/user/Info", search: `?id=${record.id}` }} >用户信息</Link>
            </p>
            <p>
                <Link to={{ pathname: "/user/AssetsLog", search: `?id=${record.id}&email=${record.email}` }} >资产记录</Link>
            </p>
        </>
    }
}];


const List: React.FC = (props) => {
    return (
        <ITable
            {...props}
            ITButton={ITButton}
            url={url}
            filter={filter}
            filterData={filterData}
            columns={columns}
            rowKey={rowKey}
        />
    )
}

export default Form.create({ name: 'List' })(List);